package acwing.算法题;
import java.math.BigInteger;
import java.util.Scanner;

/**
 * @author： li
 * @date： 2022-03-11 19:09
 * @version 1.0
 */
public class qmi {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a,b,p;
        a=sc.nextLong();
        b=sc.nextLong();
        p=sc.nextLong();
        BigInteger aa = new BigInteger(String.valueOf(a));
        BigInteger bb =new BigInteger(String.valueOf(b));
        BigInteger pp = new BigInteger(String.valueOf(p));

        System.out.println(aa.modPow(bb,pp));
        sc.close();
    }
}
